Release 10.1A: OpenEdge Development:
ProDataSets
Sample procedure: creating a view
Because the caller is selecting a subset of the fields and rows, in this case the new ProDataSet has to copy data from the original one, rather than simply assigning new buffers to the existing temp-tables in their entirety.
![]()
To update the code:
- Create the new procedure
fetchCustomTableinCodeSupport.p. It takes the table name, field list, and selectionwhere-clauseas input parameters and returns the new dynamic ProDataSet, as shown:
- Add the variables the procedure uses:
- Create a dynamic ProDataSet and a dynamic temp-table to put into it, with the fields the caller requested:
- Create a dynamic query for the temp-table in the original ProDataSet and prepares it using the where-clause passed in:
- You can open the query yourself and buffer-copy all the rows that satisfy the selection into the new temp-table:
Or, you can create a dynamic Data-Source for the temp-table in the original ProDataSet and attach that Data-Source to the new temp-table buffer in the new ProDataSet. This shows how one ProDataSet table that has already been filled can be used as a Data-Source for a table in another ProDataSet. As in this example, this is appropriate if the original ProDataSet is filled with some set of generally useful data (and possibly, data that is expensive to regenerate and that needs to be used as a cache for the session), and if the second ProDataSet only wants a subset of its rows or fields. Remember that this approach does involve copying data from one ProDataSet to another.
To use this method, remove or comment out the lines in the previous code section and replace them with this code:
- Delete the dynamic objects the procedure uses. Note that it's OK to delete the ProDataSet before returning because Progress delays the actual delete until the parameter has been returned. For example:
- Return to the window procedure
CodeWindow.wto create a user interface for the custom ProDataSet.- Add these variables to the Definitions section:
You’re going to add some
Customerfields to the window along with a Region combo box that lists the four regions in the US. When the user selects a region, the procedure runsfetchCustomTableto request a list of state codes and state names for that region. For simplicity’s sake, to reduce the size of the example somewhat, you’ll just use fields from theCustomertable directly rather than aCustomerProDataSet, which, of course, would be the proper way to do things.- From the AppBuilder palette, select the DB Fields icon and drop the fields
CustNum,Name, andCityfrom Sports2000.Customer onto the window.- Select the combo box from the palette and create a combo box. It has the Object name
cRegion, the LabelRegion,5Inner Lines, and the set ofList-Items<select>,East,West,Central,South. The<select>choice prompts the user to select a region before seeing anySalesRepsfor it, as shown
![]()
- Create another combo box called
cState, with a label ofStateand5Inner Lines as well. It has no initialList-Items. The design window should now look roughly like this:
![]()
- Code a
VALUE-CHANGEDtrigger for the Region combo box.If the user makes a region selection, the trigger runs
fetchCustomTable, requesting a ProDataSet with thettStatetable, two of the three fields from the table, and only thoseSalesRepswhere theRegionmatches the one chosen, as shown:
It empties the State combo in case this is not the first request, creates a dynamic query for it, and adds each
StateNamethat came back in the ProDataSet fromfetchCustomTableto theList-Itemsfor the State combo. It makes the first one the current choice, and deletes the query now that it’s done with it, as shown:
Now your procedures are finished. When you run the window, the standard AppBuilder-generated code opens a
Customerquery and retrieves the firstCustomerfor you because you added fields from that table to the window. You can then select aRegionand see a list of all theStatesin that region to choose from, as shown:
![]()
This illustrates how a ProDataSet that is filled with a set of useful data can be divided in many ways by other procedures that need various subsets of the data in the same session or another session. Data held in a ProDataSet in a client session can act as a cache for visual objects or client-side business logic that needs to view or use the data or a subset of the data. Any object in the same session can define its own query to browse or otherwise use a subset of the rows in the data.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |